﻿
var icon1 = new BMap.Icon('../images/map1.gif', new BMap.Size(18, 34), { anchor: new BMap.Size(9, 34) });
var icon2 = new BMap.Icon('../images/map2.gif', new BMap.Size(18, 34), { anchor: new BMap.Size(9, 34) });
var icon3 = new BMap.Icon('../images/map3.gif', new BMap.Size(18, 34), { anchor: new BMap.Size(9, 34) });
var icon4 = new BMap.Icon('../images/map4.gif', new BMap.Size(18, 34), { anchor: new BMap.Size(9, 34) });
function InitMap() {
    map = new BMap.Map("mymap");          // 创建地图实例 
    map.addControl(new BMap.MapTypeControl());   //添加地图类型控件
    map.enableScrollWheelZoom(true);
    var top_left_control = new BMap.ScaleControl({ anchor: BMAP_ANCHOR_TOP_LEFT });// 左上角，添加比例尺
    var top_left_navigation = new BMap.NavigationControl();  //左上角，添加默认缩放平移控件
    map.addControl(top_left_control);
    map.addControl(top_left_navigation);
    if (scounty != "")
        map.centerAndZoom(scounty, 11);
    else if (scity != "")
        map.centerAndZoom(scity, 11);
    else if (sprovince != "")
        map.centerAndZoom(sprovince, 11);
    else
        map.centerAndZoom("济南", 11);
    InitMapmark();
}


//预警发送人初始化
function InitSendUser() {
    $('#senduser').combotree({
        url: '../userinfo/GetLinker.ashx?action=queryt',
        multiple: true,
        width: 300,
        valueField: 'id',
        textField: 'text',
        //panelHeight: 'auto'
        panelHeight: 160

    });
    $('#mmark').ckeditor();
    //for (instance in CKEDITOR.instances)
    //    CKEDITOR.instances[instance].setData("");
}
function ShowstationName(etype) {
    if (etype == "label") { $("#CBstationname").prop("checked", !$("#CBstationname").prop("checked")); }
    if ($("#CBstationname").prop("checked")) {
        $("#mymap .BMapLabel").each(function (i) { $(this).show(); });
    }
    else {
        $("#mymap .BMapLabel").each(function (i) { $(this).hide(); });
    }
}
Array.prototype.deleteElementByValue = function (varElement) {
    var numDeleteIndex = -1;
    for (var i = 0; i < this.length; i++) {
        // 严格比较，即类型与数值必须同时相等。
        if (this[i] === varElement) {
            this.splice(i, 1);
            numDeleteIndex = i;
            break;
        }
    }
    return numDeleteIndex;
}
function sendAlarm(alarmcalss) {
    CKupdate();
    var f = $('#myalarm');
    var uids = $('#senduser').combotree('getValues');    
    var alevel = $('#alarmlevel').val();
    $.messager.progress();

        f.form('submit', {
            url: "../info/GetInfo.ashx?action=adds&uid=" + uids + "&alarmclass=" + alarmcalss,
            onSubmit: function () {
                var isval = $(this).form('validate');
                if (isval == false) $.messager.progress('close');
                return isval;
            },
            success: function (result) {
                $.messager.progress('close');
                if (result.indexOf("T") == 0) {
                    $('#dlg').dialog('close');
                    $.messager.alert("提示", "恭喜您，信息发送成功", "info");
                    $('#tt').datagrid('reload');
                }
                else if ((result.indexOf("F") == 0)) {
                    $.messager.alert("提示", "发送失败，请重新操作！", "info");
                    return;
                }
                else if ((result.indexOf("L") == 0)) {
                    $.messager.alert("提示", "长时间没有操作，请重新登录！", "info");
                    top.location = '/index.aspx';
                    return;
                }
            }
        });
}
function renderstation() {
    var html = template('tmpstations', getdata);
    $('#mystations').html(html);
}
Date.prototype.pattern = function (fmt) {
    var o = {
        "M+": this.getMonth() + 1, //月份        
        "d+": this.getDate(), //日        
        "h+": this.getHours() % 12 == 0 ? 12 : this.getHours() % 12, //小时        
        "H+": this.getHours(), //小时        
        "m+": this.getMinutes(), //分        
        "s+": this.getSeconds(), //秒        
        "q+": Math.floor((this.getMonth() + 3) / 3), //季度        
        "S": this.getMilliseconds() //毫秒        
    };
    var week = {
        "0": "/u65e5",
        "1": "/u4e00",
        "2": "/u4e8c",
        "3": "/u4e09",
        "4": "/u56db",
        "5": "/u4e94",
        "6": "/u516d"
    };
    if (/(y+)/.test(fmt)) {
        fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
    }
    if (/(E+)/.test(fmt)) {
        fmt = fmt.replace(RegExp.$1, ((RegExp.$1.length > 1) ? (RegExp.$1.length > 2 ? "/u661f/u671f" : "/u5468") : "") + week[this.getDay() + ""]);
    }
    for (var k in o) {
        if (new RegExp("(" + k + ")").test(fmt)) {
            fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
        }
    }
    return fmt;
}
function getBoundary(city) {
    var bdary = new BMap.Boundary();
    bdary.get(city, function (rs) {       //获取行政区域

        var count = rs.boundaries.length; //行政区域的点有多少个
        if (count == 0) {
            return;
        }
        var pointArray = [];
        for (var i = 0; i < count; i++) {
            ply = new BMap.Polygon(rs.boundaries[i], { strokeWeight: 2, strokeColor: "#22FF00", fillOpacity: 0, fillColor: "#FFEEEE" }); //建立多边形覆盖物
            map.addOverlay(ply);  //添加覆盖物
            pointArray = pointArray.concat(ply.getPath());
        }
        map.setViewport(pointArray);    //调整视野                 
    });
}
$.extend($.fn.tree.methods, {
    getLevel: function (jq, target) {
        var l = $(target).parentsUntil("ul.tree", "ul");
        return l.length + 1;
    }
});
function getUrlParam(name) {
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象
    var r = window.location.search.substr(1).match(reg);  //匹配目标参数
    if (r != null) return unescape(r[2]); return null; //返回参数值
}
function ConvertJSONDateToJSDate(jsondate) {
    var date = new Date(parseInt(jsondate, 10));
    return date;
}
function reloadgridTree() {
    var queryParams = $('#win').datagrid('options').queryParams;
    queryParams.sebm = sebm;

    $('#win').datagrid('options').queryParams = queryParams;
    $("#win").datagrid('reload');

}
function curmenu(id) {
    $(".menueother:contains("+id+")").attr("class", "menuecur");
}
$.extend($.fn.window.defaults, {
    collapsible: false, 	//折叠
    closable: true,         //显示右上角关闭按钮
    //closed:true,
    minimizable: false, 	//最小化
    maximizable: false, 	//最大化
    resizable: false, 	    //是否允许改变窗口大小
    title: '窗口标题', 	    //窗口标题
    modal: true, 		    //模态	
    draggable: true,        //允许拖动
    max: false
});
function serverLogin() {
    var $newpass = $('#NewPassword');
    var $rePass = $('#txtRePass');

    if ($newpass.val() == '') {
        msgShow('系统提示', '请输入密码！', 'warning');
        return false;
    }
    if ($rePass.val() == '') {
        msgShow('系统提示', '请在一次输入密码！', 'warning');
        return false;
    }

    if ($newpass.val() != $rePass.val()) {
        msgShow('系统提示', '两次密码不一至！请重新输入', 'warning');
        return false;
    }
    $.post('/userinfo/GetUser.ashx?action=chpwd&NewPassword=' + $newpass.val() + '&OldPassword=' + $('#OldPassword').val(), function (msg) {
        if (msg == "T") {
            msgShow('系统提示', '恭喜，密码修改成功！', 'info');
            $newpass.val('');
            $rePass.val('');
            closePwd();
        }
        else
            msgShow('系统提示', '密码修改失败！', 'info');
    });

}
function openPwd() {
    $('#w').window({
        title: '修改密码',
        width: 300,
        modal: true,
        shadow: true,
        closed: true,
        height: 200,
        resizable: false
    });
}
function msgShow(title, msgString, msgType) {
    $.messager.alert(title, msgString, msgType);
}
function closePwd() {
    $('#w').window('close');
}
function cutstr(str,len)
{
    var str_length = 0;
    var str_len = 0;
    str_cut = new String();
    str_len = str.length;
    for(var i = 0;i<str_len;i++)
    {
        a = str.charAt(i);
        str_length++;
        if(escape(a).length > 4)
        {
            //中文字符的长度经编码之后大于4
            str_length++;
        }
        str_cut = str_cut.concat(a);
        if(str_length>=len)
        {
            str_cut = str_cut.concat("...");
            return str_cut;
        }
    }
    //如果给定字符串小于指定长度，则返回源字符串；
    if(str_length<len){
        return  str;
    }
}
function CKupdate() {
    for (instance in CKEDITOR.instances)
        CKEDITOR.instances[instance].updateElement();
}
function addTab(subtitle,mhtml) {
    if (!$('#tab').tabs('exists', '详细信息')) {
        $('#tab').tabs('add', {
            title: '详细信息',            
            href:mhtml,
            onLoad: function () {
                var h = $(window).height() - 210;
                $('#my').height(h - 50);
                showxc();
            } ,  
            closable: true
        });
    } else {        
        var tab = $('#tab').tabs('getTab','详细信息');  // 获取选择的面板
        $('#tab').tabs('update', {
            tab: tab,
            options: {
                title: '详细信息',
                onLoad: function () {
                    var h = $(window).height() - 210;
                    $('#my').height(h - 50);
                    showxc();
                },
                href: mhtml  // 新内容的URL
            }
        });

    }    
}
function closeTab(subtitle) {
    $('#tab').tabs('close', subtitle);
}